<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>News system v1</title>


<link rel="stylesheet" type="text/css" href="style.css">


</head>

<body>



<div id="exCenter">
    <div id="exHeader">
        <center><h1><a href="index.php">Add news system v1</a></h1></center>
    </div>
    <div id="exContent">
        <div id="exLeftColumn">
            <p>
			<form name="add_form" action="add_news_mysql.php" method="post">
			<table>
				<tr>
					<td width="100">
					Title:
					</td>
					<td width="650">
					<input type="text" name="title" maxlength="20" size="20" style="width: 550px;" /> 
					</td>
				</tr>
				
				<tr>
					<td width="100">
					Description:
					</td>
					<td width="650">
					<textarea type="text" name="description"  size="20"  style="width: 550px; height: 210px"></textarea>
					</td>
				</tr>
				
				<tr>
					<td>
					Maintext:
					</td>
					<td>
					<textarea type="text" name="maintext"  size="20"  style="width: 550px; height: 210px"></textarea>
					</td>
				</tr>
				
				<tr>
					<td>
					ID_User: 
					</td>
					<td>
					
					<?PHP
					error_reporting(0);
					@ini_set(‘display_errors’, 0);
					
					$con=mysqli_connect("localhost","root","","bd_news");
					// Check connection
					if (mysqli_connect_errno()) {
					  echo "Failed to connect to MySQL: " . mysqli_connect_error();
					}					
					
					
					//echo '<input type="text" name="id_user" maxlength="20" size="20" style="width: 150px;"/>';
					
					$result = mysqli_query($con,"SELECT id_user, NICK FROM `users` WHERE `AUTHORITY_LEVEL`=1");
					
					echo '<select name="id_user" width="150" style="width: 150px">';
						while($row = mysqli_fetch_array($result)) {
						
							echo "	<option  label='".$row['NICK']."'>".$row['id_user']."</option>";
						}
					echo '</select>';
					
					?>
					
					
					</td>
				</tr>
			
				
				<tr>
					
					<td colspan="2">
						<center>
							WPISZ ID TAG
						</center>
					</td>
					<td>
					</td>
				</tr>
				
				<tr>
					
					<td>
					TAG 1 
					</td>
					<td>
					<input type="text" name="TAG1" maxlength="20" size="20" style="width: 150px;"/> 
					</td>
				</tr>
				
				<tr>
					<td>
					TAG 2
					</td>
					<td>
					 <input type="text" name="TAG2" maxlength="20" size="20" style="width: 150px;"/> 
					</td>
				</tr>
				
				
				<tr>
					<td>
					TAG 3  
					</td>
					<td>
					<input type="text" name="TAG3" maxlength="20" size="20"/> 
					</td>
				</tr>
				
				<tr>
					<td>
					TAG4:  
					</td>
					<td>
					<input type="text" name="TAG4" maxlength="20" size="20"/> 
					</td>
				</tr>
				
				<tr>
					<td colspan="2">
						<center>
							<input align="right" type="submit" name="add_usr" value="Dodaj NEWSA"/>
						</center>
					</td>
					<td>
					
					</td>
				</tr>
				
				
			</table>
			</form>
			
			
<table>


<tr>
<td = width="750">



<?PHP
//////////////////////////////
///////////////ADD TAG////////
//////////////////////////////
?>
<form name="add_tag_form" action="add_news.php?add_tag=1" method="GET">
<p>
Add tag:<input type="text" name="addtagname" maxlength="20" size="20"/>
</p>

<input type="submit" name="add_tag" value="Dodaj TAG"/>
</p>

<?PHP
	error_reporting(0);
	@ini_set(‘display_errors’, 0);

	$con=mysqli_connect("localhost","root","","bd_news");
	// Check connection
	if (mysqli_connect_errno()) {
	  echo "Failed to connect to MySQL: " . mysqli_connect_error();
	}
	
	$tagadd = $_GET['add_tag'];
	$addtagname = $_GET['addtagname'];
	
	$tagexist = mysqli_query($con,"SELECT * FROM `tags` WHERE tag='$addtagname'");
	
	
		if( mysqli_num_rows($tagexist) != 0 ){
			echo '<p>Tag alerady exist!</p>';
		}else{
			if($tagadd != '' && $addtagname !=''){
				$result = mysqli_query($con,"INSERT INTO `bd_news`.`tags` (`ID_TAG`, `TAG`) VALUES (NULL, '$addtagname');");
		//		echo "add";
				}
		}
	


	$resulttag = mysqli_query($con,"SELECT * FROM `tags`");
	echo '<br>';
	while($rowtag = mysqli_fetch_array($resulttag)) {
		echo "ID: ".$rowtag['ID_TAG']."  ".$rowtag['TAG']."<br> ";
	}

mysqli_close($con);	
?>



</form>
</td>
</tr>
</table>


      </p>
            
            
            
            
        </div>
    <div id="exRightColumn">
		
			
			<center><b>Quick menu:</b></center> <br><br>
			<a href="index.php">- Strona główna</a><Br>
			<a href="newsmyadm.php">- NewsMyAdm</a><Br>
			<a href="add_news.php">- Dodaj nowy news</a><br>            
            <a href="logout.php">- Wyloguj</a><Br><Br>
			
            <center>
			<a href="newsmyadm.php">ANULUJ DODAWANIE</a>
            </center>
            
            
        </div>
        <div class="exClear"></div>
    </div>
    <div id="exFooter">	    
	    <center>
	        <p><a href="newsmyadm.php">admin © 2014 Basinsky</a></p>
	    </center>    
    </div>
</div>




</body>

</html>